package com.example.Controller;

import com.example.Mapper.MessageMapper;
import com.example.pojo.Message;
import com.example.pojo.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@RestController

public class MessageController {
    @Resource
    private MessageMapper messageMapper;
    @GetMapping("/message")
    public Result getMessage(int sessionId){
        List<Message> messages =messageMapper.getMessagesBySessionId(sessionId);
//        把从数据库中获取的消息数据由时间降序修改为时间升序
        Collections.reverse(messages);
        return Result.success(messages);
    }
}
